package com.lagou.edu.controller;

import com.lagou.edu.pojo.User;
import com.lagou.edu.utils.ResultMode;
import org.hibernate.Session;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/user")
public class UserController {

	@ResponseBody
	@RequestMapping("/login")
	public ResultMode login(@RequestBody User user, HttpSession session ) throws Exception{
		if (StringUtils.isEmpty(user.getLoginName())){
			return new ResultMode(2,"用户名不能为空");
		}
		if (StringUtils.isEmpty(user.getPassword())){
			return new ResultMode(2,"密码不能为空");
		}
		if  (!"admin".equals(user.getLoginName())){
			return new ResultMode(2,"用户名错误");
		}
		if  (!"admin".equals(user.getPassword())){
			return new ResultMode(2,"密码错误");
		}
		session.setAttribute("username",user.getLoginName());
		return new ResultMode(1,"登录成功");
	}






}
